package com.shxc.smarttrade.old.adapternew;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.old.bean.AlphaPositionsBean;
import com.shxc.smarttrade.old.bean.RealTimeQuoteDatas;
import com.shxc.smarttrade.old.myinterface.MasterItemClickListener;
import com.shxc.smarttrade.old.myview.CustomTextView;
import com.shxc.smarttrade.old.utils.BaseUtils;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jcdev1 on 2017/5/16.
 */

public class AlphaPositionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private Context mContext;
    private LayoutInflater mInflater;
    private MasterItemClickListener listener;
    List<AlphaPositionsBean.DataBean.TraderOrderBean> mbList;

    public AlphaPositionAdapter(Context mContext) {
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);

    }

    public void setDatas(List<AlphaPositionsBean.DataBean.TraderOrderBean> mbList) {
        this.mbList = mbList;
        notifyDataSetChanged();
    }

    public void setMyItemCLickListener(MasterItemClickListener listener) {
        this.listener = listener;

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new QuotationHolder(mInflater.inflate(R.layout.adapter_alpha_position_layout, parent, false));

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof QuotationHolder) {
            AlphaPositionsBean.DataBean.TraderOrderBean tb = mbList.get(position);
            ((QuotationHolder) holder).tvChName.setText(tb.getSymbolCn());
            ((QuotationHolder) holder).tvEnName.setText(tb.getSymbolEn());
            if (tb.getCmd() == 0) {
                ((QuotationHolder) holder).tvTradeStatus.setText("涨");
                ((QuotationHolder) holder).tvTradeStatus.setBackgroundResource(R.drawable.blue_text_bg);
            } else {
                ((QuotationHolder) holder).tvTradeStatus.setText("跌");
                ((QuotationHolder) holder).tvTradeStatus.setBackgroundResource(R.drawable.orange_text_bg);
            }

            ((QuotationHolder) holder).tvDate.setText(tb.getOpenTime());
            ((QuotationHolder) holder).tvOpenPrice.setText(BaseUtils.getDigitsData(tb.getOpenPrice(), tb.getDigits()));
            ((QuotationHolder) holder).tvCurrentPrice.setText(BaseUtils.getDigitsData(tb.getClosePrice(), tb.getDigits()));
            ((QuotationHolder) holder).tvValume.setText(BaseUtils.getDigitsData(tb.getVolume(), 2));
            if (tb.getProfit() > 0) {
                ((QuotationHolder) holder).tvFloatPrice.setTextColor(mContext.getResources().getColor(R.color.tab_text));
            } else {
                ((QuotationHolder) holder).tvFloatPrice.setTextColor(mContext.getResources().getColor(R.color.stock_fell_color));
            }
            ((QuotationHolder) holder).tvFloatPrice.setText(BaseUtils.dealSymbol(tb.getProfit()));
        }

    }

    @Override
    public int getItemCount() {
        return mbList == null ? 0 : mbList.size();
    }

    public void setUpdateList(List<RealTimeQuoteDatas.DataBean.QuoteBean> updateList) {

    }


    public class QuotationHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_ch_name)
        CustomTextView tvChName;
        @BindView(R.id.tv_en_name)
        CustomTextView tvEnName;
        @BindView(R.id.tv_trade_status)
        TextView tvTradeStatus;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_open_price)
        TextView tvOpenPrice;
        @BindView(R.id.tv_current_price)
        TextView tvCurrentPrice;
        @BindView(R.id.tv_valume)
        TextView tvValume;
        @BindView(R.id.tv_float_price)
        TextView tvFloatPrice;

        QuotationHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            AutoUtils.autoSize(view);
        }
    }

}
